package cn.itrip.biz.service;

import cn.itrip.beans.domain.ItripAreaDic;
import cn.itrip.beans.vo.AreaDicVo;
import cn.itrip.beans.vo.HtoCityVo;
import cn.itrip.common.RedisAPI;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itrip.dao.ItripAreaDicMapper;
import jdk.nashorn.internal.runtime.arrays.IteratorAction;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HoteService {
    @Resource
    private ItripAreaDicMapper itripAreaDicMapper;
    @Resource
    private RedisAPI redisAPI;
    public static final String KEY_HOT_CITY = "Biz:HotelService:queryhotcity";
    public List<HtoCityVo> queryhotcity(Integer isChina){
        String key = KEY_HOT_CITY+":"+isChina;
        String value = redisAPI.get(key);
        List<HtoCityVo> list = null;
        if(value == null){
            list = itripAreaDicMapper.selectHotCit(isChina);
            redisAPI.set(key, JSONObject.toJSONString(list));
        }else{
            list = JSONArray.parseArray(value,HtoCityVo.class);
        }
        return list;
    }

    public List<AreaDicVo> querytradearea(Integer parentId) {
       return itripAreaDicMapper.querytradearea(parentId);
    }
}
